#include "GraphWidgetLine.h"

#include <QDebug>

#include <QGLWidget>

GraphWidgetLine::GraphWidgetLine()
{
}

GraphWidgetLine::GraphWidgetLine(const GraphWidgetLine &gwl) :
    GraphWidgetObject(gwl)
{
}

GraphWidgetLine::GraphWidgetLine(QVector<int> yValues, double xStart, double xInterval, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    double j = xStart;
    for (int i = 0; i < yValues.count(); i++, j+=xInterval) {
        QPointF point(j, yValues[i]);

        this->appendPoint(point);
    }

}

GraphWidgetLine::GraphWidgetLine(QVector<float> yValues, double xStart, double xInterval, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    double j = xStart;
    for (int i = 0; i < yValues.count(); i++, j+=xInterval) {
        QPointF point(j, yValues[i]);

        this->appendPoint(point);
    }

}

GraphWidgetLine::GraphWidgetLine(QVector<double> yValues, double xStart, double xInterval, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    double j = xStart;
    for (int i = 0; i < yValues.count(); i++, j+=xInterval) {
        QPointF point(j, yValues[i]);

        this->appendPoint(point);
    }

}

GraphWidgetLine::GraphWidgetLine(QVector<QPointF> values, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    foreach (QPointF point, values)
        this->appendPoint(point);
}

GraphWidgetLine::GraphWidgetLine(QLine newLine, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    this->appendPoint(QPointF(newLine.p1()));
    this->appendPoint(QPointF(newLine.p2()));
}

GraphWidgetLine::GraphWidgetLine(QLineF newLine, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    this->appendPoint(newLine.p1());
    this->appendPoint(newLine.p2());
}

void GraphWidgetLine::draw(QPen pen)
{
    glColor4f(pen.color().redF(), pen.color().greenF(), pen.color().blueF(), pen.color().alphaF());
    glLineWidth(pen.widthF());
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_DOUBLE, 0, points.data());
    glDrawArrays(GL_LINE_STRIP, 0, points.count());
//    glPointSize(pen.widthF());
//    glDrawArrays(GL_POINTS, 0, points.count());
    glDisableClientState(GL_VERTEX_ARRAY);
}
